home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / MATH / FSULTRA1.ZIP / DEMO.C next >
Text File  |  1992-06-18  |  3KB  |  71 lines

  1. /* 
  2. FSU - ULTRA    The greatest random number generator that ever was
  3.         or ever will be.  Way beyond Super-Duper.
  4.         (Just kidding, but we think its a good one.)
  5.  
  6. Authors:    Arif Zaman (arif@stat.fsu.edu) and
  7.         George Marsaglia (geo@stat.fsu.edu).
  8.  
  9. Date:        27 May 1992
  10.  
  11. Version:    1.05
  12.  
  13. Copyright:    To obtain permission to incorporate this program into
  14.         any commercial product, please contact the authors at
  15.         the e-mail address given above or at
  16.  
  17.         Department of Statistics and
  18.         Supercomputer Computations Research Institute
  19.         Florida State University
  20.         Tallahassee, FL 32306.
  21.  
  22. See Also:    README        for a brief description
  23.         ULTRA.DOC    for a detailed description
  24.  
  25. -----------------------------------------------------------------------
  26. */ 
  27. /******************************************************************
  28.  *   This demo calls the various subroutines of ultra as a test   *
  29.  *                                                                *
  30.  *   It prints the first few and the 10,000-th values that are    *
  31.  *   returned by the various routines, after the initialization   *
  32.  *   to the default rinit(1234567,7654321).                       *
  33.  *                                                                *
  34.  *   This serves as a test, for any implementation, but the       *
  35.  *   output often varies in the last digit for the floating       *
  36.  *   point numbers due to rounding methods for printouts.         *
  37.  ******************************************************************/
  38.  
  39. #include "ultra.h"
  40.  
  41. #define test(format,x,function,n)                \
  42.   rinit(1234567,7654321); for (i=1;i<10001;i++) { x=function();    \
  43.   if ((i<n) || (i==10000)) printf(format,x);    };  printf("\n");
  44.  
  45. main()
  46. { short    i;
  47.   float f;
  48.   double d;
  49.   long  l;
  50.  
  51.   printf("\nA Sample Printout:\n");
  52.   printf("No rinit call: ");
  53.   for (i=1;i<10001;i++) 
  54.   if ((i<4) || (i==10000)) printf("%16li",i32bit()); else i32bit();
  55.   printf("\n");
  56.  
  57.   printf("Signed 4 byte: "); test("%16li",l, i32bit,4);
  58.   printf("Uns. 4 byte:   "); test("%16li",l, i31bit,4);
  59.   printf("Signed 2 byte: "); test("%8hi",l,  i16bit,8);
  60.   printf("Uns. 2 byte:   "); test("%8hi",l,  i15bit,8);
  61.   printf("Signed byte:   "); test("%4hi",l,  i8bit,16);
  62.   printf("Uns. byte:     "); test("%4hi",l,  i7bit,16);
  63.   printf("Random bits:   "); test("%2hi",l,  i1bit,32);
  64.   printf("Signed Single: "); test("%16.7f",f,   vni,4);
  65.   printf("Uns. Single:   "); test("%16.7f",f,   uni,4);
  66.   printf("Signed Double: "); test("%32.15lg",d,dvni,2);
  67.   printf("Unsigned Dble: "); test("%32.15lg",d,duni,2);
  68.  
  69.   return 0;
  70. }
  71.